<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class InventoryControl extends CI_Controller{

	public function index()
	{
		$this->load->library('session');
		$this->load->helper('form');
		$this->load->model('product');
		
		$dataa = array();
		$in = 0;
		foreach($this->product->getProduct() as $prod)
		{
			$pro['name'] = $prod->name;
			$pro['price'] = $prod->price;
			$pro['quantity'] = $prod->quantity;
			$pro['id'] = $prod->id;
			$dataa[$in] = $pro;
			$in++;
		}
		
		$data['prods'] = $dataa;

		$this->load->view('product', $data);
		
	}
	
	public function emailSent()
	{
		$this->load->view('emailSent');
	}
	
	public function process()
	{
		$this->load->helper('url');
		$this->load->library('email');
		$this->email->from('shop@deep-beta.co.uk', 'Need Products');
		$this->email->to('lukasz.iwanski@gmail.com'); 
		
		$this->email->subject('Need More of: '.$_POST['name']);
		$this->email->message('
		Shop 1 needs more:	
		'. $_POST['name']." 
		ID of product: ".$_POST['id']);	

		$this->email->send();
		echo "<pre>";
			echo $this->email->print_debugger();
		echo "</pre>";
		//update the product
		redirect('/inventoryControl/emailSent', 'refresh');
	}
}

